package com.freak.wanandroid.dialog;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.freak.wanandroid.R;
import com.freak.wanandroid.bean.SystemClassChildrenEntity;
import com.freak.wanandroid.model.system.adapter.SecondClassifyAdapter;

import java.util.List;


/**
 * 体系二级分类弹窗
 */
@Deprecated
public class SystemSecondDialogFragment extends DialogFragment implements View.OnClickListener {
    private Dialog mDetailDialog;

    private TextView mTvSystemTitle;

    private LinearLayout mLlSystemCancel;

    private SecondClassifyAdapter mSystemSecondAdapter;

    private RecyclerView mSystemSecondRecycle;

    private LinearLayout mSystemSecondNoData;

    private List<SystemClassChildrenEntity> mChildrenList;

    private SystemClassChildrenEntity mChildren;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        mDetailDialog = new Dialog(getActivity(), R.style.dialog);
        mDetailDialog.setContentView(R.layout.dialog_look_c2c);
        mDetailDialog.setCancelable(true);
        mTvSystemTitle = mDetailDialog.findViewById(R.id.tv_system_title);
        mLlSystemCancel = mDetailDialog.findViewById(R.id.ll_system_cancel);
        mSystemSecondRecycle = mDetailDialog.findViewById(R.id.system_second_recycle);
        mSystemSecondNoData = mDetailDialog.findViewById(R.id.system_second_no_data);
        mSystemSecondRecycle.setLayoutManager(new LinearLayoutManager(getActivity()));
        mChildrenList = (List<SystemClassChildrenEntity>) getArguments().getSerializable("mChildrenList");

        // 二级分类recycleView
//        if (mChildrenList != null && mChildrenList.size() != 0) {
//            mSystemSecondNoData.setVisibility(View.GONE);
//            mSystemSecondRecycle.setVisibility(View.VISIBLE);
//            if (mSystemSecondAdapter == null) {
////                mSystemSecondAdapter = new SecondClassifyAdapter(getActivity(), mChildrenList);
//                mSystemSecondRecycle.setAdapter(mSystemSecondAdapter);
//                mSystemSecondAdapter.setOnItemClick(new MBaseAdapter.MOnItemClickListener() {
//                    @Override
//                    public void onItemClick(int position, Object o) {
//                        mChildren= (SystemClassChildrenEntity) o;
//                        if (onTipsListener!=null){
//                            onTipsListener.onSuccess(mChildren.getName(),mChildren.getChildrenId());
//                        }
//                        mDetailDialog.dismiss();
//                    }
//                });
//            } else {
//                mSystemSecondAdapter.setData(mChildrenList);
//                mSystemSecondAdapter.notifyDataSetChanged();
//            }
//        } else {
//            mSystemSecondNoData.setVisibility(View.VISIBLE);
//            mSystemSecondRecycle.setVisibility(View.GONE);
//        }
        mTvSystemTitle.setText(getArguments().getString("tipsTitle"));
        mLlSystemCancel.setOnClickListener(this);
        return mDetailDialog;
    }

    private OnTipsListener onTipsListener;

    public void setOnConfirmListener(@NonNull OnTipsListener onTipsListener) {
        this.onTipsListener = onTipsListener;
    }

    public interface OnTipsListener {
        void onCancel();

        void onSuccess(String name,int id);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.ll_system_cancel) {
            mDetailDialog.dismiss();
            if (onTipsListener != null) {
                onTipsListener.onCancel();
            }
        }
    }
}

